﻿using FwtXnaCommon.Maps;
using FwtXnaCommon.Scripts;
using FwtXnaGame3.Tools;
using GpgCore.Maps;
using GpgCore.Products;
using GpgGame.GameObjects.MapItems;
using Microsoft.Xna.Framework;

namespace GpgGame.GameObjects.PlanetMaps
{
    public class VisualPlanetMapCell : MapCell
    {
        public PlanetMapCell MapCell;

        public VisualPlanetMapCell()
        {
            Sprite = GeneralFactory.CreateOnePxSprite(true);
        }

        public override void Start()
        {
            base.Start();
            IsCheckMouseEvents = true;
            IsDrawServiceShadow = true;
            IsDrawGui = true;
            AddScript(new ButtonScript(this));
        }

        public void TakeYourInfo(PlanetMapCell pmCell)
        {
            MapCell = pmCell;
            switch (MapCell.CellType)
            {
                case PlanetMapCellType.Ocean:
                    Transform2D.Color = Color.DarkBlue;
                    break;
                case PlanetMapCellType.Plains:
                    Transform2D.Color = Color.DarkGreen;
                    break;
                case PlanetMapCellType.Mounts:
                    Transform2D.Color = Color.Gray;
                    break;
                case PlanetMapCellType.Hills:
                    Transform2D.Color = Color.DarkOliveGreen;
                    break;
            }

            if (MapCell.City != null)
            {
                var vcity = AddObject(new VisualCity(MyScene, MapCell.City));
            }
        }

        public override void Update(GameTime gameTime)
        {
            if (GodObject.SelectedCity != null && GodObject.SelectedCity == MapCell.BelongsToCity)
                Transform2D.Color = Color.Green;
            else
                Transform2D.Color = Color.DarkGreen;
            base.Update(gameTime);
        }

        public override void DrawGui()
        {
            if (MapCell.Minerals != null)
            {
                var txt = string.Format("{0}\r\n{1}", MapCell.Minerals.ProdType, MapCell.Minerals.Count);
                SpriteBatch.DrawTextCenter(txt, Transform2D.AbsolutePosition, Color.White, GodObject.CellInfoFont);
            }
            base.DrawGui();
        }
    }
}
